home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / tpbuf11.zip / TPBUFFER.PAS < prev    next >
Pascal/Delphi Source File  |  1993-06-24  |  3KB  |  95 lines

  1. Unit TPbuffer;
  2.  
  3. (* TP-Buffer unit version 1.1 /Update              *)
  4. (* Using the keyboard's buffer in Turbo Pascal     *)
  5. (* This unit is released to the public domain      *)
  6. (* by Lavi Tidhar on 5-10-1992                     *)
  7.  
  8. (* This unit adds three special functions not      *)
  9. (* incuded in the Turbo Pascal regular package     *)
  10.  
  11. (* You may alter this source code, move the        *)
  12. (* procedures to your own programs. Please do      *)
  13. (* NOT change these lines of documentation         *)
  14.  
  15. (* This source might teach you about how to        *)
  16. (* use interrupts in pascal, and the keyboard's    *)
  17. (* buffer. from the other hand, it might not :-)   *)
  18.  
  19. (* Used: INT 16, functions 0 and 1                 *)
  20. (*       INT 21, function 0Ch                      *)
  21.  
  22. (* INT 16 - KEYBOARD - READ CHAR FROM BUFFER, WAIT IF EMPTY
  23.            AH = 00h
  24.            Return: AH = scan code
  25.                    AL = character         *)
  26.  
  27. (* INT 16 - KEYBOARD - CHECK BUFFER, DO NOT CLEAR
  28.            AH = 01h
  29.            Return: ZF = 0 character in buffer
  30.                        AH = scan code
  31.                        AL = character
  32.                        ZF = 1 no character in buffer *)
  33.  
  34. (* INT 21 - DOS - CLEAR KEYBOARD BUFFER
  35.         AH = 0Ch
  36.         AL must be 1, 6, 7, 8, or 0Ah.
  37.         Notes: Flushes all typeahead input, then executes function specified by AL
  38.         (effectively moving it to AH and repeating the INT 21 call).
  39.         If AL contains a value not in the list above, the keyboard buffer is
  40.         flushed and no other action is taken. *)
  41.  
  42. (* For more details/help etc, you can contact me on: *)
  43.  
  44. (* Mail: Lavi Tidhar
  45.          46 Bantam Dr.
  46.          Blairgowrie
  47.          2194
  48.          South Africa 
  49. *)
  50.  
  51. (* Phone:
  52.           International: +27-11-787-8093
  53.           South Africa:  (011)-787-8093
  54. *)
  55.  
  56. (* Netmail: The Catacomb BBS 5:7101/45 (fidonet)
  57.             The Catacomb BBS 80:80/100 (pipemail)
  58. *)
  59.  
  60. Interface
  61.  
  62. Uses Dos;
  63.  
  64. Function GetScanCode:Byte; (* Get SCAN CODE from buffer, wait if empty *)
  65. Function GetKey:Char;      (* Get Char from buffer, do NOT wait *)
  66. Procedure FlushKB;
  67.  
  68. Implementation
  69.  
  70. Function GetKey:Char;
  71.  Var Regs:Registers;
  72.  Begin
  73.   Regs.AH:=1;                (* Int 16 function 1 *)
  74.   Intr ($16,Regs);           (* Read a charecter from the keyboard buffer *)
  75.   GetKey:=Chr (Regs.AL);     (* do not wait. If no char was found, CHR(0) *)
  76.  End;                        (* (nul) is returned *)
  77.  
  78. Function GetScanCode:Byte;   (* Int 16 function 0 *)
  79.  Var Regs:Registers;         (* The same as CRT's Readkey, but gives you *)
  80.   Begin                      (* the scan code. Esp usefull when you want to *)
  81.    Regs.AH:=0;               (* use special keys as the arrows, there will *)
  82.    Intr ($16,Regs);          (* be a conflict when using ReadKey *)
  83.    GetScanCode:=Regs.AH;
  84.   End;
  85.  
  86. Procedure FlushKB;           (* INT 21 function 0C *)
  87.  Var Regs:Registers;         (* Flushes (erase) the keyboard buffer *)
  88.   Begin                      (* ONLY. No other function is executed *)
  89.    Regs.AH:=$0C;
  90.    Regs.AL:=2;
  91.    Intr ($21,Regs);
  92.   End;
  93.  
  94. End.
  95.